// 高阶函数：参数是个函数或则返回值为一个函数
// 1.必须函数 2.参数为一个函数或则返回值为一个函数
import { useParams, useSearchParams, useLocation, useNavigate } from 'react-router-dom'
function WithRouter(Component) {
   function ComponentHook(props) {
      let params = useParams();
      let searchParams = useSearchParams();
      let loaction = useLocation();
      let navigate = useNavigate();
      // 获取 当前路由路径
      let path = loaction.pathname;
      let active = 0;
      switch (path) {
         case '/index/home':
            active = 0;
            break;
         case '/index/cart':
            active = 1;
            break;
         case '/index/mine':
            active =2
            break;
         default:
            active=0
      }
      return <Component {...props} router={{ params, searchParams, loaction, navigate }} active={active}></Component>
   }
   return ComponentHook;
}

export default WithRouter;